{extend name="platform/base" /} {block name="main"}
<section class="panel panel-default">
	<header class="panel-heading text-right bg-light">
		<ul class="nav nav-tabs pull-left">
<!-- 			<li class="active"><a href="#wpay" data-toggle="tab">微信支付</a></li> -->
			<li class=""><a href="#alipay" data-toggle="tab">银联卡支付</a></li>
<!-- 			<li class=""><a href="#otherpay" data-toggle="tab">其他支付方式</a></li> -->
		</ul>
		<span class="hidden-sm">支付设置</span>
	</header>
	<div class="panel-body">
		<div class="tab-content">

			<div class="tab-pane fade active in" id="alipay">
					<div class="panel-body">
						<form class="form-horizontal" id="alipay_form">
							
							<div class="form-group">
								<label class="col-sm-2 control-label">商户号：</label>
								<div class="col-md-4">
								<input type="text" class="form-control" id="merchant_number" required value="{$config.value.merchant_number}">
									
								</div>
								<label class="col-md-6 error" for="merchant_number" class="error"></label>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">签名证书秘钥：</label>
								<div class="col-md-4">
								<input type="text" class="form-control" id="certificate_key" required value="{$config.value.certificate_key}">
								</div>
								<label class="col-md-6 error" for="certificate_key" class="error"></label>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-lg-2 control-label">手续费：</label>
								<div class="col-md-4">
								<input type="number" class="form-control" id="service_charge" required value="{$config.value.service_charge}">
									
								</div>
								<label class="col-md-6 error" for="service_charge" class="error"></label>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">是否启用支付</label>
								<div class="col-md-4">
									<label class="switch">
										<input type="checkbox" id="is_use" {if condition="$config.is_use eq 1"}checked{/if}>
										<span></span>
									</label>
								</div>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">是否启用退款</label>
								<div class="col-md-4">
									<label class="switch">
										<input type="checkbox" id="refund_is_use" name="refund_is_use" {if condition="$config.value.refund_is_use eq 1"}checked="checked"{/if} >
										<span></span>
									</label>
									<div style="color: #999;">开启支付宝支付才可以进行后续操作</div>
								</div>
							</div>
							
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<button type="submit" class="btn btn-primary" onclick="setConfigAjax()">保存</button>
								</div>
							</div>
						</form>
					</div>
			</div>
			
		</div>
	</div>
</section>
<script type="text/javascript">
function setConfigAjax(){

	var merchant_number = $("#merchant_number").val();
	var certificate_key = $("#certificate_key").val();
	var service_charge = $("#service_charge").val();
	var is_use = 0;
	
	if($("#is_use").is(":checked")){
		is_use = 1;
	}

	var refund_is_use = $("input[name='refund_is_use']:checked").val() ? 1 : 0;

  	if(merchant_number == ''){
		$("#merchant_number").focus().parent().next().html("请输入正确的商户号").show();
		return false;
	}
	if(certificate_key == ''){
		$("#certificate_key").focus().parent().next().html("请输入正确的签名证书秘钥").show();
		return false;
	}
	if(service_charge == ''){
		$("#service_charge").focus().parent().next().html("请输入手续费").show();
		return false;
	}else if(service_charge<0){
		$("#service_charge").focus().parent().next().html("最低提现金额必须大于0").show();
		return false;
	}


	$.ajax({
		type:"post",
		url:"{:__URL('PLATFORM_MAIN/config/unionPayConfig')}",
		data:{
			'merchant_number':merchant_number,
			'certificate_key':certificate_key,
			'service_charge':service_charge,
			'refund_is_use' :refund_is_use,
			'is_use' : is_use,
			'type' : 'unionpay',
		},
		success:function (data) {
			if (data["code"] > 0) {
				showTip(data["message"],"success");
				location.href=__URL("PLATFORM_MAIN/config/paymentconfig");
			}else{
				showTip(data["message"],"error");
			}
		}
	}); 
}
</script>
{/block}
